package com.colin.utils;


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class FileUtil {

	public static String readFile2String(File file,String code){
		StringBuilder sb = new StringBuilder();
		InputStream is = null;
		InputStreamReader isr = null;
		BufferedReader br = null;
		try{
			is = new FileInputStream(file);
			isr = new InputStreamReader(is,code);
			br = new BufferedReader(isr);
			String tmp = null;
			while((tmp = br.readLine())!=null){
				sb.append(tmp).append("\r\n");
			}
		}catch(Exception e){
		}finally{
			try {
				br.close();
				isr.close();
				is.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return sb.toString();
	}
	
	
	public static List<String> readFile2List(File file,String code){
		List<String> list = new ArrayList<String>();
		if(file.exists()){
			InputStream is = null;
			InputStreamReader isr = null;
			BufferedReader br = null;
			try{
				is = new FileInputStream(file);
				isr = new InputStreamReader(is,code);
				br = new BufferedReader(isr);
				String tmp = null;
				while((tmp = br.readLine())!=null){
					list.add(tmp);
				}
			}catch(Exception e){
			}finally{
				try {
					br.close();
					isr.close();
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			
		}else{
		}
		return list;
	}

}
